package com.example.blog.config;

import com.example.blog.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.resource.NoResourceFoundException;

/**
 * 统一异常处理
 */
@Slf4j
@RestControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler
    public Result<?> handle(Exception e) {
        log.error("异常信息：", e);
        return Result.fail("内部错误");
    }

    @ExceptionHandler
    public Result<?> handle(NoResourceFoundException e) {
        log.error("文件不存在：{}", e.getResourcePath());
        //log.error("异常信息：", e);
        return Result.fail("内部错误");
    }
}
